import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.ParameterMetaData;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Administrator
 * Date: 2023-08-17
 * Time: 17:37
 */
public class JDBCDemo {
    public static void main(String[] args) throws SQLException {

        Scanner scanner = new Scanner(System.in);
/*        System.out.println("请输入学号:");
        int id = scanner.nextInt();
        System.out.println("请输入姓名:");
        String name = scanner.next();*/


        DataSource dataSource = new MysqlDataSource();
        ((MysqlDataSource) dataSource).setUrl("jdbc:mysql://127.0.0.1:3306/java108?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource) dataSource).setUser("root");
        ((MysqlDataSource) dataSource).setPassword("112233");

        Connection connection = dataSource.getConnection();

        String sql = "insert into emp values\n" +
                "('小花','女','生产',13000),\n" +
                "('小张','男','生产',9800),\n" +
                "('小王','女','销售',8000),\n" +
                "('小吴','女','市场',6000),\n" +
                "('小赵','男','人力',12000),\n" +
                "('小吴','女','人力',11000);";

        PreparedStatement statement = connection.prepareStatement(sql);
/*        statement.setInt(1,id);
        statement.setString(2,name);*/

        int n = statement.executeUpdate();
        System.out.println("n =" + n);

        statement.close();
        connection.close();

    }
}
